<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use Session;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
    public function index(){
        return view('admin/login.index');
    }
    public function register(){
        $res = DB::table('property_user')->get();
        return view('admin/login.register',['data'=>$res]);
    }
    public function login_res(Request $request){
        $res = DB::table('property_user')->where([
            ['property_name', '=', $request->property_user],
            ['property_pwd', '=', $request->property_pwd],
        ])->first();
        if(!empty($res)){
            session_start();
            Session::push('property_id', $res->property_id);
            Session::push('property_name', $res->property_name);
            return 1;
        }else{
            return 2;
        }
    }
    public function register_res(Request $request){
        $sale_user = $request->sale_user;
        $sale_pwd = $request->sale_pwd;
        $sale_property_id = $request->sale_property_id;
        $sale_tel = $request->sale_tel;
        $data = DB::table('sale_user')->insert([
            'sale_user' => $sale_user,
            'sale_pwd' => $sale_pwd,
            'property_id' => $sale_property_id,
            'sale_tel' => $sale_tel,
        ]);

        if($data){
            return 1;
        }else{
            return 0;
        }

    }
}
